﻿Imports System.IO

Partial Public Class frm_ReImpresion2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Listado.Visible = False
            Listado.UpdateAfterCallBack = True
        End If
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Dim strFileSize As String = ""
        Dim dirXML As New IO.DirectoryInfo(ConfigurationManager.AppSettings("pathXML"))
        Dim aryFi As IO.FileInfo() = dirXML.GetFiles("*.xml")
        Dim fi As IO.FileInfo

        Dim szArchivosGenerados As String = ""
        Dim szArchivosNoGenerados As String = ""

        lstArchivosNoGenerados.Items.Clear()
        lstArchivosGenerados.Items.Clear()

        lstArchivosNoGenerados.UpdateAfterCallBack = True
        lstArchivosGenerados.UpdateAfterCallBack = True

        For Each fi In aryFi
            If Not File.Exists(fi.FullName.Replace(".xml", ".pdf")) Then
                Dim docXml As New System.Xml.XmlDocument
                Dim strSystem = ConfigurationManager.AppSettings.GetValues("strSystem")
                Dim strPlt = ConfigurationManager.AppSettings.GetValues("strPlt")
                Dim PathPDF = ConfigurationManager.AppSettings.GetValues("pathPDF")
                Dim PathXML = ConfigurationManager.AppSettings.GetValues("PathXML")
                Dim szPathPDF As String
                Dim szPathXML As String

                szPathPDF = PathPDF(0).ToString & fi.Name.Replace(".xml", ".pdf")
                szPathXML = fi.FullName

                Dim objPrint As New PrintServer.FOPPdfDriver
                Dim Resp

                Try
                    Resp = objPrint.ExecutePdf(strSystem(0).ToString, strPlt(0).ToString, szPathXML, szPathPDF)
                Catch ex As Exception

                End Try

                If Not Resp Then
                    lstArchivosNoGenerados.Items.Add(fi.Name.Replace(".xml", ""))
                    'Anthem.Manager.AddScriptForClientSideEval("alert('" & objPrint.glsReply & "');")
                Else
                    lstArchivosGenerados.Items.Add(fi.Name.Replace(".xml", ""))
                End If

                objPrint = Nothing
            End If
        Next

        Masivo.Visible = False
        Masivo.UpdateAfterCallBack = True

        Listado.Visible = True
        Listado.UpdateAfterCallBack = True

        lstArchivosNoGenerados.UpdateAfterCallBack = True
        lstArchivosGenerados.UpdateAfterCallBack = True
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Response.Redirect("frm_DatosSimulacion.aspx")
    End Sub
End Class